package com.gj.xxl.job.executor.jobhandler;

import com.gj.xxl.job.core.handler.annotation.GjJob;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;

@Component
public class SampleJob {

    private SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy:MM:dd HH:mm:ss");

    @GjJob("helloworld")
    public void hello() {
        System.out.println("hello world");
    }

    @GjJob("test1")
    public void test1() {
        try {
            Thread.sleep(2 * 1000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }

        System.out.println(">>>>>>>>>>>>>> job1 被执行了 " + simpleDateFormat.format(new Date()));
    }


    @GjJob("test2")
    public void test2() {
        System.out.println(">>>>>>>>>>>>>> job2 被执行了" + simpleDateFormat.format(new Date()));

//        while (true) {
//            System.out.println(Thread.currentThread() + ": hello world");
//            try {
//                Thread.sleep(500);
//            } catch (InterruptedException e) {
//                throw new RuntimeException(e);
//            }
//        }
    }

}
